/*
 * main.cpp
 *
 *  Created on: 09.02.2013
 *      Author: Maksim Lazeba
 */

#include <vector>
#include <iostream>
#include <fstream>
#include <algorithm>

bool in_bounds(std::vector<double> p, std::vector<double> lb, std::vector<double> rt)
{
	for (size_t i = 0; i < p.size(); i++)
	{
		if (p[i] < lb[i] || p[i] > rt[i])
			return false;
	}
	return true;
}

int main(int argc, char* argv[]){
        std::ifstream in(argv[1]);
        int d, n, m;
        in >> d >> n >> m;
        std::vector<std::vector<double>> points;
        for(int i = 0; i < n; i++){
                std::vector<double> point(d);
                for(int j = 0; j < d; j++){
                        in >> point[j];
                }
                points.push_back(point);
        }



        std::vector<std::vector<int>> ans;
        for(int j = 0; j < m; j++){
                std::vector<double> lb(d);
                std::vector<double> rt(d);
                for(int i = 0; i < d; i++)
                        in >> lb[i];
                for(int i = 0; i < d; i++)
                        in >> rt[i];

                std::vector<int> answer;

                for(int i = 0; i < n; i++)
                {
                	if (in_bounds(points[i],lb,rt))
                		answer.push_back(i + 1);
                }
                std::sort(answer.begin(), answer.end());
                ans.push_back(answer);
        }

        in.close();
        std::ifstream input(argv[2]);

        std::vector<std::vector<int>> testans;

        int value = 0;
        for(int i = 0; i < m; i++){
                input >> value;
                std::vector<int> cur(value);
                for(int j = 0; j < value; j++){
                        input >> cur[j];
                }
                std::sort(cur.begin(), cur.end());
                testans.push_back(cur);
        }

        if(testans.size() != ans.size()){
                return 1;
        }

        for(size_t i = 0; i < ans.size(); i++){
                if(ans[i].size() != testans[i].size()){
                        return 1;
                }
                if(ans[i] != testans[i]){
                        return 1;
                }
        }
        input.close();
        return 0;
}


